package com.hrbxlh.constants;

/**
 * -------------------------------------------------------
 * Copyright (c) 2017, 鑫联华信息科技股份有限公司
 * All rights reserved.
 * FileName：VirtualMachineStatusEnum.java
 * Description：虚拟机状态枚举类
 * History：
 * Date           Author               Desc
 * 2017.5.5	       王晨                建立
 * -------------------------------------------------------
 */
public enum VirtualMachineStatusEnum {
    UNALLOCATED(1, "未分配"),
    ALLOCATED(2, "已分配"),
    ERROR(3, "故障"),
    UNRECOGNIZED(4, "未知");

    private Integer code;

    private String msg;

    VirtualMachineStatusEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * @description 根据状态码获取枚举常量
     * @param code
     * @return
     */
    public static VirtualMachineStatusEnum codeOf(int code) {
        for (VirtualMachineStatusEnum status : values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return UNRECOGNIZED;
    }
}
